﻿using CtCommon.Utility;
using Dapper;
using Newtonsoft.Json;
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Windows.Forms;
using Ct.StudentProject.Data;


namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            TextBox textBox1 = new TextBox();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        public void button1_Click(object sender, EventArgs e)
        {

            student stu = new student(userName.Text, Name.Text, IDnumber.Text, Password.Text);
            string jsonText = JsonConvert.SerializeObject(stu);
            MessageBox.Show(jsonText);
            student user = jsonText.JSONDeserialize<student>();

            try
            {

                string msg = string.Empty;
                Deliver del = new Deliver();

                bool isvaild = del.VerifyAndDeliver(user, out msg);

                if (isvaild)
                {
                    MessageBox.Show(msg);
                }
                else
                {
                    msg = string.Empty;
                    StudentDatabase db = new Ct.StudentProject.Data.StudentDatabase();
                    if (db.InsertStudent(user) == true)
                    {
                        MessageBox.Show("ID为"+msg);
                    }
                }

            }
            catch (InvalidCastException)
            {
                MessageBox.Show("注册异常，请重试");
            }

        }
    }
}
